import org.openqa.selenium.By;

import java.io.IOException;

/**
 * @projectName: The-examination-questionnaire-pass-test
 * @package: PACKAGE_NAME
 * @className: TemplatePage
 * @author: Tongxinxin
 * @description: 模块广场页面功能测试
 * @date: 2025/9/22 0:34
 * @version: 1.0
 */
public class TemplatePage extends Util{
    public TemplatePage(String url) {
        super(url);
    }
    public static String url="http://8.155.1.153:8081/template";
    //未登录状态下进入我的项目页面
    public void NoLoginTemplate() throws IOException {
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.top___1C1Zi > div.header___5xZ3f > span"));

        //判断是否返回登录页面
        String expect=driver.getTitle();

        getScreenShot(getClass().getName());
        assert expect.equals("问卷考试系统");
    }
    //模板测试功能
    public void LoginTemplate() throws IOException {
        //进行登录
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //点击模板广场
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child.ant-pro-base-menu-menu-item > span > div > span.ant-pro-base-menu-item-text.ant-pro-base-menu-item-text-has-icon")).click();
        //点击添加模板
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button > span")).click();
        //编辑模板
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button:nth-child(5) > span")).click();
        //点击保存
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button:nth-child(5) > span")).click();
        //输入新增模板名称
        driver.findElement(By.cssSelector("")).sendKeys("111");
        //分类五号
        driver.findElement(By.cssSelector("#category")).sendKeys("五号");
        //添加到共有库
        driver.findElement(By.cssSelector("#survey-modal-container > div > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-body > form > div:nth-child(4) > div > div > div > div > label > span.ant-checkbox > input")).click();
        //点击保存
        driver.findElement(By.cssSelector("#survey-modal-container > div > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-footer > button.ant-btn.ant-btn-primary > span")).click();

        //点击关闭
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm.ant-btn-dangerous > span")).click();
        //点击私有库查看是否创建成功
        driver.findElement(By.cssSelector("#rc-tabs-19-tab-private")).click();
        //检查是否创建成功
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.cardList > div > div > div > div > div > div > div > div > div.ant-card-body > div.ant-card-meta > div > div.ant-card-meta-title > a"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("111");

    }

    //测试查询功能
    public void LoginIq() throws IOException, IOException {
        //进行登录
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //点击模板广场
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child.ant-pro-base-menu-menu-item > span > div > span.ant-pro-base-menu-item-text.ant-pro-base-menu-item-text-has-icon")).click();
        //点击搜索框搜索模板“zzz"
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > input")).sendKeys("111");
        //点击"搜模板"按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > span > button > span")).click();

        //检查是否创建成功,出现”暂无数据“表示搜索失败
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.cardList > div > div > div > div > div > div.ant-empty-description"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("暂无数据");
    }

}
